package york.Game;

import java.awt.Point;

public class Vector2D {
	public double x;
	public double y;
	
	public Vector2D() {
		x = y = 0;
	}
	
	public Vector2D(Point a_Point) {
		x = a_Point.x;
		y = a_Point.y;
	}
	public Vector2D(double a_x,double a_y) {
		x = a_x;
		y = a_y;
	}
	public Vector2D(Vector2D a_Vec) {
		x = a_Vec.x;
		y = a_Vec.y;
	}
	
	
	public void set(Point a_Loc) {
		x = (double)a_Loc.x;
		y = (double)a_Loc.y;
	}
	
	public void add(Vector2D a_Vec) {
		x += a_Vec.x;
		y += a_Vec.y;
	}
	
	public void Multiply(double a_Mult) {
		x *= a_Mult;
		y *= a_Mult;
	}
	
	public void subtract(Vector2D a_Vec) {
		x -= a_Vec.x;
		y -= a_Vec.y;
	}
	
	public void divide(double dividend) {
		x /= dividend;
		y /= dividend;
	}
	
	/**
	 * Returns the angle between two vectors in radians
	 * @param a_Vec
	 * @return
	 */
	public double angle(Vector2D a_Vec) {
		return this.dot(a_Vec) * (Math.PI / 180);
	}
	
	/**
	 * Returns the angle between two vectors in degress
	 * @param a_Vec
	 * @return
	 */
	public double dot(Vector2D a_Vec) {
		return x * a_Vec.x + y * a_Vec.y;
	}
	
	public double length() {
		return Math.sqrt(dot(this));
	}
	
	public void normalize() {
		double TempLen = this.length();
		x /= TempLen;
		y /= TempLen;
	}
	public double distance(Vector2D a_Vec) {
		return Math.sqrt(Math.pow(x - a_Vec.x,2) + Math.pow(y - a_Vec.y,2));
	}
	
	public Vector2D Perpendicular() {
		return new Vector2D(-y,x);
	}
}
